package com.gaga.console.core.controller.bv;


import com.gaga.common.path.ApiPath;
import com.gaga.common.result.Result;
import com.gaga.console.base.controller.BaseController;
import com.gaga.console.core.entity.dto.*;
import com.gaga.console.core.service.AudioPlayQueueService;
import com.gaga.console.core.service.BvAudioPlayService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.FileNotFoundException;


/**
 * 用户信息表 前端控制器
 *
 * @author liujia
 * @since 2025-03-27
 */
@RestController
@RequestMapping(ApiPath.ROOT + "/bv/live")
public class BvAudioPlayController extends BaseController {

    @Autowired
    private BvAudioPlayService bvAudioPlayService;

    @Autowired
    private AudioPlayQueueService audioPlayQueueService;

    @ApiOperation(value = "开始直播")
    @PostMapping("/start")
    public Result start(@RequestBody StartLiveDto dto) throws FileNotFoundException {
        bvAudioPlayService.startLive(dto);
        return Result.ok();
    }

    @ApiOperation(value = "生成音频")
    @PostMapping("/generate")
    public Result generate(@RequestBody PlayDto dto) throws FileNotFoundException {
        bvAudioPlayService.generate(dto);
        return Result.ok();
    }

    @ApiOperation(value = "停止直播")
    @PostMapping("/stop")
    public Result stop() {
        bvAudioPlayService.stopLive();
        return Result.ok();
    }

    @ApiOperation(value = "更新直播间实时人数")
    @PostMapping("/updateUserCount")
    public Result updateUserCount(@RequestBody UpdateRealTimeDataDto dto) {
        bvAudioPlayService.updateUserCount(dto);
        return Result.ok();
    }

    @ApiOperation(value = "获取直播间状态")
    @PostMapping("/getLiveRoomStatus")
    public Result getLiveRoomStatus() {
        return Result.ok(bvAudioPlayService.getStartLiveStep());
    }

    @ApiOperation(value = "实时调整音频速度")
    @PostMapping("/realTimeChangeSpeed")
    public Result realTimeChangeSpeed(@RequestBody RealTimeChangeSpeedDto dto) {
        audioPlayQueueService.realTimeChangeSpeed(dto);
        return Result.ok();
    }

    @ApiOperation(value = "实时调整音量")
    @PostMapping("/realTimeChangeVolumn")
    public Result realTimeChangeVolumn(@RequestBody RealTimeChangeVolumnDto dto) {
        audioPlayQueueService.realTimeChangeVolumn(dto);
        return Result.ok();
    }

    @ApiOperation(value = "实时调整音频音效")
    @PostMapping("/realTimeChangeGainDb")
    public Result realTimeChangeGainDb(@RequestBody RealTimeChangeGainDbDto dto) {
        audioPlayQueueService.realTimeChangeGainDb(dto);
        return Result.ok();
    }

    @ApiOperation(value = "开始避音")
    @PostMapping("/startMute")
    public Result startMute() {
        audioPlayQueueService.startMute();
        return Result.ok();
    }

    @ApiOperation(value = "结束避音")
    @PostMapping("/endMute")
    public Result endMute() {
        audioPlayQueueService.endMute();
        return Result.ok();
    }

}
